﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Group.aspx.cs" Inherits="Account_Group" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <asp:GridView ID="GridViewGroup" runat="server" AutoGenerateColumns="False" DataKeyNames="Id"
        DataSourceID="SqlDataSource1" BackColor="White" BorderColor="#3366CC" 
        BorderStyle="None" BorderWidth="1px" CellPadding="4" Width="100%">
        <Columns>
            <asp:HyperLinkField HeaderText="Group name" SortExpression="Name" DataTextField="Name"
                ItemStyle-Width="400" DataNavigateUrlFields="Id" 
                DataNavigateUrlFormatString="~/Account/ViewGroup.aspx?id={0}" >
<ItemStyle Width="400px"></ItemStyle>
            </asp:HyperLinkField>
            <asp:BoundField DataField="Owner" HeaderText="Created by" SortExpression="Owner" />
            <asp:BoundField DataField="c" HeaderText="Message" SortExpression="Date" />
            <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
        </Columns>
        <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
        <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
        <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
        <RowStyle BackColor="White" ForeColor="#003399" />
        <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
        <SortedAscendingCellStyle BackColor="#EDF6F6" />
        <SortedAscendingHeaderStyle BackColor="#0D4AC4" />
        <SortedDescendingCellStyle BackColor="#D6DFDF" />
        <SortedDescendingHeaderStyle BackColor="#002876" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT  g.Id, g.Name, g.Owner, g.Date, COUNT(m.id) AS c
FROM              [Group] AS g LEFT OUTER JOIN
                            GroupMessage AS m ON g.Id = m.GroupId
                            WHERE g.Status=1
GROUP BY   g.Id, g.Name, g.Owner, g.Date
ORDER BY   g.Date DESC" UpdateCommand="UPDATE [Group] SET [Name] = @Name, [Owner] = @Owner, [Date] = @Date WHERE [Id] = @Id">
    </asp:SqlDataSource>
    <asp:Panel ID="Panel1" runat="server" GroupingText="New group">
        Group name
        <asp:TextBox ID="tbName" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Create" OnClick="Button1_Click" />
    </asp:Panel>
</asp:Content>
